package priv.wangy.micro.common.sync.producer;

import jakarta.annotation.Resource;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @author zhangjq
 * @since 2023-12-18
 */
@Component
@Scope("prototype")
public class DataSyncProducer extends AbstractDataSyncProducer {

    @Resource
    private RabbitTemplate template;

    @Override
    public void notice() {
        MessageProperties messageProperties = new MessageProperties();
        messageProperties.setContentEncoding("UTF-8");
        messageProperties.setContentType("text/plain");
        String data = LocalDateTime.now().format(DateTimeFormatter.ISO_LOCAL_DATE_TIME);
        Message message = new Message(data.getBytes(StandardCharsets.UTF_8), messageProperties);
        template.convertAndSend(this.getExchange(), "", message);
    }
}
